var file;
filename=argument0;
file = file_text_open_write(filename);
SaveFile = file;

// Write file
writeLine('<?xml version="1.0" encoding="UTF-8"?>');
writeLine("<system>");
writeLine("<entities>");

for(i=0;i<instance_number(Entity);i+=1)
{
    ii = instance_find(Entity, i);
    if (ii.entity != noone)
    {
        writeLine('<entity sprite="'+ sprite_get_name(ii.artsprite) +'">');
        writeLine('<x>' + string(ii.x) + '</x>');
        writeLine('<y>' + string(ii.y) + '</y>');
        writeLine('<rotation>' + string(ii.image_angle) + '</rotation>');
        writeLine("</entity>");
    }
}
writeLine("</entities>");
writeLine("<components>");
for(i=0;i<instance_number(Component);i+=1)
{
    ii = instance_find(Component, i);
    switch(ii.type)
    {
        case "question_multi":
            if (ii.object_index == QuestionMultiChoice)
            {
                writeLine('<component sprite="'+ sprite_get_name(ii.sprite_index) +'">');
                writeLine('<x>' + string(ii.x) + '</x>');
                writeLine('<y>' + string(ii.y) + '</y>');
                writeLine('<width>' + string(ii.width) + '</width>');
                writeLine('<height>' + string(ii.height) + '</height>');
                writeLine('<rotation>' + string(ii.image_angle) + '</rotation>');
                writeLine('<question name="' + ii.question + '">');
                writeAnswers(ii);
                writeLine('</question>');
                writeLine('<behaviour>');
                writeEvents(ii);
                writeLine('</behaviour>');
                writeLine("</component>");
            }
        break;
    }
}
writeLine("</components>");
writeLine("</system>");
file_text_close(file);
